import axios from "axios";
import Cookies from "js-cookie";
const http = axios.create({
    baseURL:"http://localhost:8080/api1",
    timeout:10000,
})
// 请求拦截
http.interceptors.request.use((config)=>{
    config.headers["Content-Type"] = "application/json"
    config.headers["Authorization"] = `Bearer ${Cookies.get("token")}`;
    return config;
},(error)=>{
    return Promise.reject(error)
})
// 响应拦截
http.interceptors.response.use((response)=>{
    console.log(response);
    if(response.data.code!==10000){
        this.$message({
            message: response.data.message,
            type: 'error'
        });
        this.$router.push("/404");
    }
    return response;
},(error)=>{
    return Promise.reject(error)
})
export default http;